using UnityEngine;
using System.Collections;

public class I_Jogar : MonoBehaviour 
{
	private int id = 0;
	private Vector2 screen;
	private AudioClip click;
	
	void Start () 
	{
		this.screen.y = GameObject.Find("Main Camera").GetComponent<Camera>().orthographicSize;
		this.screen.x = this.screen.y * GameObject.Find("Main Camera").GetComponent<Camera>().aspect;
		
		this.gameObject.AddComponent("MeshRenderer");
		this.gameObject.AddComponent("MeshFilter");
		this.gameObject.AddComponent("BoxCollider");
		
		this.gameObject.GetComponent<BoxCollider>().size = new Vector3(this.screen.x * 0.3f, this.screen.y * 0.2f, 0.1f);
		
		Mesh mesh = Quad.Create (this.screen.x * 0.15f, this.screen.y * 0.1f);
		
		this.gameObject.GetComponent<MeshFilter>().mesh = mesh;
		this.gameObject.GetComponent<MeshRenderer>().material = AtlasInstru.globalMaterial;
		
		this.transform.position = new Vector3(-this.screen.x * 0.25f, -3.0f, 0);
		
		this.gameObject.AddComponent("AudioSource");
		
		this.click = (AudioClip)Resources.Load("Audio/Click");
		
		this.gameObject.audio.clip = this.click;
	}
	
	void Update () 
	{
		this.gameObject.GetComponent<MeshFilter>().mesh.uv = new Vector2[]
		{
			new Vector2(AtlasInstru.rects[id].xMin, AtlasInstru.rects[id].yMax),
			new Vector2(AtlasInstru.rects[id].xMax, AtlasInstru.rects[id].yMax),
			new Vector2(AtlasInstru.rects[id].xMax, AtlasInstru.rects[id].yMin),
			new Vector2(AtlasInstru.rects[id].xMin, AtlasInstru.rects[id].yMin)
		};
	}
	
	void OnMouseEnter()
	{
		this.transform.localScale += new Vector3(0.1f, 0.1f, 0);
	}
	
	void OnMouseExit()
	{
		this.transform.localScale -= new Vector3(0.1f, 0.1f, 0);
	}
	
	void OnMouseDown()
	{
		this.gameObject.audio.Play();
		Application.LoadLevel("Jogo");
	}
}
